#!/usr/bin/python
import os
from mylocale import gettext, LOCALES
from functools import partial
from string import Template
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class cron_handler(webapp.RequestHandler):
  def get(self):
    _ = gettext
    locales = self.request.accept_language.best_matches('en-us')
    current_locale = 'en-us'
    for locale in locales:
      locale = locale.lower()
      if locale in LOCALES:
        _ = partial(gettext, locale=locale)
        current_locale = locale
        break
    template_values = {'appid': os.environ['APPLICATION_ID']}
    path = os.path.join(os.path.dirname(__file__), 'html/%s/index.html' % current_locale)
    fp = open(path, 'r')
    content = fp.read()
    fp.close()
    self.response.out.write(Template(content).safe_substitute(template_values))

  def head(self):
    return

  def post(self):
    return


class wave_handler(webapp.RequestHandler):
  def get(self, *args):
    return

  def head(self, *args):
    return

  def post(self, *args):
    return


if __name__ == "__main__":
  application = webapp.WSGIApplication([('/_wave/robot/profile', wave_handler),
                                        ('/.*', cron_handler)])
  run_wsgi_app(application)
